<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">

                <h:outputStylesheet library="css" name="printing.css" ></h:outputStylesheet>

                <h:form>

                    <p:panel header="Patient Details" styleClass="alignTop" style="height: 600px;">
                        <h:panelGrid columns="1" >
                            <h:panelGrid columns="2" >
                                <p:outputLabel value="Search Type" />
                                <p:selectOneRadio value="#{patientController.reportKeyWord.string}" >
                                    <f:selectItem itemLabel="All" itemValue="0" />
                                    <f:selectItem itemLabel="Active" itemValue="1" />
                                    <f:selectItem itemLabel="De-Active" itemValue="2" />
                                </p:selectOneRadio>
                                <p:outputLabel value="Only Registed Patient" />
                                <p:selectBooleanCheckbox value="#{patientController.reportKeyWord.additionalDetails}" >
                                    <f:ajax event="change" execute="@this" render="selectMem" />
                                </p:selectBooleanCheckbox>
                                <p:outputLabel value="Search Record Count" />
                                <p:inputText value="#{patientController.reportKeyWord.numOfRows}" />
                                <h:outputLabel value="Membership"/>
                                <p:selectOneMenu id="selectMem" value="#{patientController.reportKeyWord.membershipScheme}" style="width: 290px;" 
                                                 disabled="#{!patientController.reportKeyWord.additionalDetails}" >
                                    <f:selectItem itemLabel="Select Membership" />
                                    <f:selectItems value="#{membershipSchemeController.items}" var="t" itemLabel="#{t.name}" itemValue="#{t}"/>
                                </p:selectOneMenu>
                                <p:commandButton value="Process" ajax="false" action="#{patientController.createPatientList()}" />
                                <p:commandButton value="Excel" ajax="false">
                                    <pe:exporter type="xlsx" target="tblBills" fileName="patent_list"  />
                                </p:commandButton>
                            </h:panelGrid>
                            <p:panel id="panelSearch" header="Patient Details" styleClass="summeryBorder" >
                                <p:dataTable value="#{patientController.patientList}" var="p" rowIndexVar="i" id="tblBills"
                                             rowStyleClass="#{p.retired ? 'redText':''}" >
                                    <p:column >
                                        <f:facet name="header" >
                                            <p:outputLabel value="No" />
                                        </f:facet>
                                        <h:outputLabel value="#{i+1}" />
                                    </p:column>
                                    <p:column sortBy="#{p.person.nameWithTitle}" style="min-width: 300px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Name" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.person.nameWithTitle}" />
                                    </p:column>
                                    <p:column >
                                        <f:facet name="header" >
                                            <p:outputLabel value="NIC" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.person.nic}"/>
                                    </p:column>
                                    <p:column sortBy="#{p.code}">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Code" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.code}" />
                                    </p:column>
                                    <p:column style="min-width: 100px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Update Status" />
                                        </f:facet>
                                        <p:commandButton value="Re-Active" action="#{patientController.activePatient(p)}" 
                                                         rendered="#{p.retired eq true}" ajax="false"
                                                         disabled="#{!webUserController.hasPrivilege('MemberShipMemberReActive')}" 
                                                         onclick="if (!confirm('Are you sure you want to Re-Active this Patient?'))
                                                                     return false;" />
                                        <p:commandButton value="De-Active" action="#{patientController.deActivePatient(p)}" 
                                                         rendered="#{p.retired eq false}" ajax="false"
                                                         disabled="#{!webUserController.hasPrivilege('MemberShipMemberDeActive')}" 
                                                         onclick="if (!confirm('Are you sure you want to De-Active this Patient?'))
                                                                     return false;" />
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header" >
                                            <p:outputLabel value="Membership" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.person.membershipScheme.name}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header" >
                                            <p:outputLabel value="Membership" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.person.phone}"/>
                                    </p:column>
                                    <p:column>
                                        <f:facet name="header" >
                                            <p:outputLabel value="PHN" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.phn}"/>
                                    </p:column>
                                    <p:column sortBy="#{p.person.area.name}" >
                                        <f:facet name="header" >
                                            <p:outputLabel value="Area" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.person.area.name}"/>
                                    </p:column>
                                    <p:column >
                                        <f:facet name="header" >
                                            <p:outputLabel value="Sex" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.person.sex}" />
                                    </p:column>
                                    <p:column style="min-width: 300px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Address" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.person.address}" />
                                    </p:column>
                                    <p:column sortBy="#{p.person.dob}" style="min-width: 80px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Date of Birth" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.person.dob}" >
                                            <f:convertDateTime pattern="dd MM yyyy"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column sortBy="#{p.createdAt}" style="min-width: 160px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Created At" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.createdAt}" >
                                            <f:convertDateTime pattern="yyyy MM dd hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column style="max-width: 160px;">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Creater" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.creater.webUserPerson.name}" />
                                    </p:column>
                                    <p:column >
                                        <f:facet name="header" >
                                            <p:outputLabel value="Bill" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.bill.insId}" />
                                    </p:column>
                                    <p:column style="min-width: 160px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Bill Created At" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.bill.createdAt}" >
                                            <f:convertDateTime pattern="yyyy MM dd hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column style="min-width: 160px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Last Editer" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.editer.webUserPerson.name}" />
                                    </p:column>
                                    <p:column style="min-width: 160px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Last Edited At" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.editedAt}" >
                                            <f:convertDateTime pattern="yyyy MM dd hh:mm:ss a"/>
                                        </h:outputLabel>
                                    </p:column>
                                    <p:column style="min-width: 90px">
                                        <f:facet name="header" >
                                            <p:outputLabel value="Comment" />
                                        </f:facet>
                                        <h:outputLabel value="#{p.retireComments}" />
                                    </p:column>
                                    
                                </p:dataTable>
                            </p:panel>
                        </h:panelGrid>
                    </p:panel>

                </h:form>

            </ui:define>



        </ui:composition>

    </h:body>
</html>
